//
//  SINAMyPartTimeJobTableViewCell.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/4.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINAMyPartTimeJobTableViewCell.h"
#import "SINACircularBeadUtils.h"
#import "SINACalendarUtils.h"

@interface SINAMyPartTimeJobTableViewCell ()

//头像

@property (weak, nonatomic) IBOutlet UIImageView *titleImageView;
//姓名 服务类型
@property (weak, nonatomic) IBOutlet UILabel *userNameAndServiceTypeLabel;
//订单状态
@property (weak, nonatomic) IBOutlet UILabel *orderStuteLabel;
//任务完成
@property (weak, nonatomic) IBOutlet UILabel *taskComlpeLabel;
//任务取消
@property (weak, nonatomic) IBOutlet UILabel *taskCanleLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *serviceTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *moneyNumberLabel;
//收货地址
@property (weak, nonatomic) IBOutlet UILabel *shopAdrees;

@end

@implementation SINAMyPartTimeJobTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self setBackgroundColor:[UIColor colorWithHexString:@"#fafafa"]];
    [SINACircularBeadUtils makeCircularView:self.titleImageView];
    [SINACircularBeadUtils makeCircularBead:3 andView:self.taskComlpeLabel andIsSetBackground:YES];
    [SINACircularBeadUtils makeCircularBead:3 andView:self.taskCanleLabel andIsSetBackground:YES];
}
-(void)setMyEntrustModel:(SINAStudentServiceMyEntrustModel *)myEntrustModel{
    _myEntrustModel=myEntrustModel;
    
    WeakSelf;
    
    if (self.itemBlock) {
        [[SINAUiviewClickLiserner alloc]viewClickFunction:self.contentView andWithBlick:^(UIView *view) {
            weakSelf.itemBlock(self.pos, 4, nil, myEntrustModel);
        }];
    }
    
    
    
    //我发的委托 1001  刚刚发出的  取消委托  取消订单
    //我发的委托 1000  刚刚发出的 未被接单
    //我发的委托 1006  刚刚发出的 已接单
    //我发的委托 1009  刚刚发出的 已完成 未评价
    //我发的委托 1010  刚刚发出的 已完成 已评价
    NSString *orderStute = myEntrustModel.orderStute;
    
    //类型 1 我发布的委托  2 我给别人的委托
    NSInteger itemType = myEntrustModel.itemType;
    if (itemType==1) {
        
        
        if([orderStute intValue]==1000){
            self.orderStuteLabel.text=@"未接单";
            self.taskComlpeLabel.text=@"取消订单";
            self.taskComlpeLabel.hidden=NO;
            self.taskCanleLabel.hidden=YES;
            
            
        }else if([orderStute intValue]==1001){
            self.orderStuteLabel.text=@"订单已关闭";
            self.taskComlpeLabel.text=@"取消订单";
            self.taskComlpeLabel.hidden=YES;
            self.taskCanleLabel.hidden=YES;
        }else if([orderStute intValue]==1006){
            self.orderStuteLabel.text=@"已接单";
            self.taskComlpeLabel.text=@"任务完成";
            self.taskComlpeLabel.hidden=NO;
            self.taskCanleLabel.text=@"取消委托";
            self.taskCanleLabel.hidden=NO;
        } else if([orderStute intValue]==1009){
            self.orderStuteLabel.text=@"已完成";
            self.taskComlpeLabel.text=@"评价订单";
            self.taskComlpeLabel.hidden=NO;
            self.taskCanleLabel.hidden=YES;
        }
        else if([orderStute intValue]==1010){
            self.orderStuteLabel.text=@"已完成";
            self.taskComlpeLabel.text=@"评价订单";
            self.taskComlpeLabel.hidden=YES;
            self.taskCanleLabel.hidden=YES;
        }
    } else {
        
        if([orderStute intValue]==1000){
            self.orderStuteLabel.text=@"未接单";
            self.taskComlpeLabel.text=@"取消订单";
            self.taskComlpeLabel.hidden=NO;
            self.taskCanleLabel.hidden=YES;
        }else if([orderStute intValue]==1001){
            self.orderStuteLabel.text=@"订单已关闭";
            self.taskComlpeLabel.text=@"取消订单";
            self.taskComlpeLabel.hidden=YES;
            self.taskCanleLabel.hidden=YES;
        }else if([orderStute intValue]==1006){
            self.orderStuteLabel.text=@"已接单";
            self.taskComlpeLabel.text=@"任务完成";
            self.taskComlpeLabel.hidden=NO;
            self.taskCanleLabel.text=@"取消委托";
            self.taskCanleLabel.hidden=NO;
        } else if([orderStute intValue]==1009){
            self.orderStuteLabel.text=@"已完成";
            self.taskComlpeLabel.text=@"评价订单";
            self.taskComlpeLabel.hidden=NO;
            self.taskCanleLabel.hidden=YES;
        }
        else if([orderStute intValue]==1010){
            self.orderStuteLabel.text=@"已完成";
            self.taskComlpeLabel.text=@"评价订单";
            self.taskComlpeLabel.hidden=YES;
            self.taskCanleLabel.hidden=YES;
        }
    }
    
    
    if ([orderStute integerValue]==1000||[orderStute integerValue]==1001) {
        if ([myEntrustModel.userName isEqualToString:@"***"]) {
            self.userNameAndServiceTypeLabel.text=[NSString stringWithFormat:@"%@  (%@)",myEntrustModel.selfUserName,myEntrustModel.serviceType];
        }else{
            self.userNameAndServiceTypeLabel.text=[NSString stringWithFormat:@"%@  (%@)",myEntrustModel.userName,myEntrustModel.serviceType];
        }
        
        if (myEntrustModel.userTitleImageUrl==nil) {
            [self.titleImageView sd_setImageWithURL:[NSURL URLWithString:myEntrustModel.selfUserTitleImageUrl] placeholderImage:[UIImage imageNamed:@"默认头像"]];
        }
        
    }else{
        
        self.userNameAndServiceTypeLabel.text=[NSString stringWithFormat:@"%@  (%@)",myEntrustModel.userName,myEntrustModel.serviceType];
        
        
        
        [self.titleImageView sd_setImageWithURL:[NSURL URLWithString:myEntrustModel.userTitleImageUrl] placeholderImage:[UIImage imageNamed:@"默认头像"]];
    }
    
    self.phoneLabel.text=myEntrustModel.contactPhoneNumber;
    
    NSString *startTime = myEntrustModel.serviceStartTime;
    NSString *stopTime = myEntrustModel.serviceStopTime;
    if (stopTime==nil||startTime==nil||[startTime integerValue]==0||[stopTime integerValue]==0) {
        self.serviceTimeLabel.text=[NSString stringWithFormat:@"异常"];
    }else{
        
        self.serviceTimeLabel.text=[NSString stringWithFormat:@"%@-%@",[SINACalendarUtils getDateStringWithTimeStr:startTime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:stopTime andFormat:@"HH:mm"]];
    }
    self.moneyNumberLabel.text=[NSString stringWithFormat:@"%@ RMB",myEntrustModel.moneyNumber];
    self.shopAdrees.text = myEntrustModel.shippingAddress;
    
    
    
    //
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.taskComlpeLabel andWithBlick:^(UIView *view) {
        [weakSelf commlpeEntrusTaksk:myEntrustModel];
    }];
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.taskCanleLabel andWithBlick:^(UIView *view) {
        DLog(@"取消委托");
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"确定取消委托" sureBtn:@"确认"
                                                             cancleBtn:@"取消"];
        alertView.resultIndex = ^(NSInteger index) {
            //取消订单
            [weakSelf canleEntrusOrder:myEntrustModel];
        };
        [alertView showXLAlertView];
    }];
    
}

-(void) commlpeEntrusTaksk:(SINAStudentServiceMyEntrustModel*) myEntrustModel{
    WeakSelf;
    //我发的委托 1001  刚刚发出的  取消委托  取消订单
    //我发的委托 1000  刚刚发出的 未被接单
    //我发的委托 1006  刚刚发出的 已接单
    //我发的委托 1009  刚刚发出的 已完成 未评价
    //我发的委托 1010  刚刚发出的 已完成 已评价
    NSInteger orderStute = [myEntrustModel.orderStute integerValue];
    
    //类型 1 我发布的委托  2 我给别人的委托
//    NSInteger itemType = myEntrustModel.itemType;
    
    if (orderStute ==1000) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"确定取消订单" sureBtn:@"确认"
                                                             cancleBtn:@"取消"];
        alertView.resultIndex = ^(NSInteger index) {
            //取消订单
            [weakSelf canleEntrusOrder:myEntrustModel];
        };
        [alertView showXLAlertView];
        
    }else if (orderStute ==1006) {
        //任务完成
        if (self.itemBlock) {
            self.itemBlock(0, 2, nil, myEntrustModel);
        }
    }else if (orderStute ==1009) {
        //评价订单
        if (self.itemBlock) {
            self.itemBlock(0, 3, nil, myEntrustModel);
        }
    }
}
//取消订单
//取消委托
-(void) canleEntrusOrder:(SINAStudentServiceMyEntrustModel*) myEntrustModel{
    if (self.itemBlock) {
        self.itemBlock(0, 1, nil, myEntrustModel);
    }
}

-(void)setMyPartTimeJobModel:(SINAMyPartTimeJobModel *)myPartTimeJobModel{
    _myPartTimeJobModel = myPartTimeJobModel;
    
    self.userNameAndServiceTypeLabel.text=[NSString stringWithFormat:@"%@  (%@)",myPartTimeJobModel.userName,myPartTimeJobModel.serviceType];
    
    //我发的委托 1001  刚刚发出的  取消委托  取消订单
    //我发的委托 1000  刚刚发出的 未被接单
    //我发的委托 1006  刚刚发出的 已接单
    //我发的委托 1009  刚刚发出的 已完成 未评价
    //我发的委托 1010  刚刚发出的 已完成 已评价
    NSString *orderStute = myPartTimeJobModel.orderStute;
    
    DLog(@"我的兼职 状态 %@",orderStute);
    
    self.taskCanleLabel.hidden=YES;
    self.taskComlpeLabel.hidden = NO;
    
    if([orderStute intValue]==1000){
        self.orderStuteLabel.text=@"已发布";
        self.taskComlpeLabel.text=@"取消订单";
    }else if([orderStute intValue]==1001){
        self.orderStuteLabel.text=@"已关闭";
        self.taskComlpeLabel.text=@"任务完成";
        self.taskComlpeLabel.hidden = YES;
    }else if([orderStute intValue]==1006){
        self.orderStuteLabel.text=@"已委托";
        self.taskComlpeLabel.text=@"任务完成";
        self.taskComlpeLabel.hidden = NO;
    }else if([orderStute intValue]==1009){
        self.orderStuteLabel.text=@"已完成";
        self.taskComlpeLabel.text=@"评价订单";
        self.taskComlpeLabel.hidden = NO;
    }else if([orderStute intValue]==1010){
        self.orderStuteLabel.text=@"已完成";
        self.taskComlpeLabel.text=@"评价订单";
        self.taskComlpeLabel.hidden = YES;
    }
     [self.titleImageView sd_setImageWithURL:[NSURL URLWithString:myPartTimeJobModel.userTitleImageUrl] placeholderImage:[UIImage imageNamed:@"默认头像"]];
    self.phoneLabel.text=myPartTimeJobModel.contactPhoneNumber;
    
    NSString *startTime = myPartTimeJobModel.serviceStartTime;
    NSString *stopTime = myPartTimeJobModel.serviceStopTime;
    if (stopTime==nil||startTime==nil||[startTime integerValue]==0||[stopTime integerValue]==0) {
        self.serviceTimeLabel.text=[NSString stringWithFormat:@"异常"];
    }else{
        
        self.serviceTimeLabel.text=[NSString stringWithFormat:@"%@-%@",[SINACalendarUtils getDateStringWithTimeStr:startTime andFormat:@"HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:stopTime andFormat:@"HH:mm"]];
    }
    self.moneyNumberLabel.text=[NSString stringWithFormat:@"%@ RMB",myPartTimeJobModel.moneyNumber];
    self.shopAdrees.text = myPartTimeJobModel.shippingAddress;
    
    
    if ([orderStute integerValue]==1006||[orderStute integerValue]==1009||[orderStute integerValue]==1010) {
        [self.titleImageView sd_setImageWithURL:[NSURL URLWithString:myPartTimeJobModel.otherUserTitleImageUrl] placeholderImage:[UIImage imageNamed:@"默认头像"]];
        self.userNameAndServiceTypeLabel.text=[NSString stringWithFormat:@"%@  (%@)",myPartTimeJobModel.otherUserNikName,myPartTimeJobModel.serviceType];
        
    }
    
    WeakSelf;
    
    if (self.itemBlock) {
        [[SINAUiviewClickLiserner alloc]viewClickFunction:self.contentView andWithBlick:^(UIView *view) {
            weakSelf.itemBlock(self.pos, 1, myPartTimeJobModel, nil);
        }];
        
        [[SINAUiviewClickLiserner alloc]viewClickFunction:self.taskComlpeLabel andWithBlick:^(UIView *view) {
            weakSelf.itemBlock(self.pos, 2, myPartTimeJobModel, nil);
        }];
    }
    
    
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
